package com.skp.shaphan.io;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class InsertDataWriter extends StringBasedDataWriter {
	private String insertStatementStart;

	@Override
	public void closeRow() {
		super.closeRow();
		println(");");
	}

	@Override
	public void setMetaData(ResultSetMetaData meta) throws SQLException {
		super.setMetaData(meta);
		insertStatementStart = "insert into inserttable values(";
		/*
		for(int x=1; x<=meta.getColumnCount(); x++) {
			if(x > 1) {
				insertStatementStart += ",";
			}
		}
		*/
	}

	@Override
	protected void writeNewRowData() {
		super.writeNewRowData();
		print(insertStatementStart);
	}

	@Override
	protected void writeCellData(String data, int columnNumber) {
		super.writeCellData(data, columnNumber);
		if(columnNumber > 1) {
			print(", ");
		}
		print("'" + data + "'");
	}

}
